import MyPromise from "./index.js";

export function promisify(fn) {
  return function (...args) {
    return new MyPromise((resolve, reject) => {
      fn(...args, (err, data) => {
        if (err) reject(err);
        resolve(data);
      });
    });
  };
}

export function promisifyAll(obj) {
  Object.keys(obj).forEach((key) => {
    obj[`${key}Async`] = promisify(obj[key]);
  });
}
